package com.zhou.common.mybatis.template.shiro.subscriber;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.event.Subscribe;
import org.springframework.stereotype.Component;

import java.util.EventObject;

@Slf4j
@Component
public class TestSubscriber {

    int fooCount, barCount;
    Object lastEvent;

    public TestSubscriber() {
        fooCount = barCount = 0;
    }

    @Subscribe
    public void onFooEvent(FooEvent event) {
        fooCount++;
        lastEvent = event;
        log.info("foo size {}", fooCount);
    }

    @Subscribe
    public void onBarEvent(BarEvent event) {
        barCount++;
        lastEvent = event;

        log.info("bar size {}", barCount);

    }

    int getCount() {
        return fooCount + barCount;
    }

    public static class FooEvent extends EventObject {

        public FooEvent(Object source) {
            super(source);
        }
    }

    public static class BarEvent extends FooEvent {

        public BarEvent(Object source) {
            super(source);
        }
    }
}
